import axios from 'axios'
import { Modal } from 'iview'
import store from './store'
var instance = axios.create({ //axios的全局配置-
    baseURL: 'http://localhost:10995/api/', //全局变量--本地地址
    // baseURL: 'http://120.77.69.221:8101/api/', //全局变量--正式地址
    // baseURL: 'http://115.29.104.243:63331/api/', //全局变量--测试地址
    headers: { 'X-Requested-With': 'XMLHttpRequest' }, //请求头
    withCredentials: true
});
instance.interceptors.request.use(config => {
    store.dispatch('loadingShow');
    return config;
}, function(error) {
    console.log(error);
    store.dispatch('loadingHide');
    return Promise.reject(error);
});
instance.interceptors.response.use(response => {
    store.dispatch('loadingHide');
    return response
}, function(error) {
    Modal.warning({ title: "提示信息", content: "网络异常,请稍后重试!!!" });
    console.log(error);
    store.dispatch('loadingHide');
    return Promise.reject(error);
});

export default instance